package com.lyb.spzx.product.controller;

import com.github.pagehelper.PageInfo;
import com.lyb.spzx.model.dto.h5.ProductSkuDto;
import com.lyb.spzx.model.dto.product.SkuSaleDto;
import com.lyb.spzx.model.entity.product.Product;
import com.lyb.spzx.model.entity.product.ProductSku;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import com.lyb.spzx.model.vo.h5.ProductItemVo;
import com.lyb.spzx.product.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品列表接口")
@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    ProductService productService;

    @Operation(summary = "分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSku>> findAllProduct(@PathVariable Integer page,
                                                       @PathVariable Integer limit,
                                                       ProductSkuDto productSkuDto){
        PageInfo<ProductSku> skuPageInfo = productService.findAllProduct(page, limit, productSkuDto);
        return Result.build(skuPageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "商品详情接口")
    @GetMapping("/item/{skuId}")
    public Result<ProductItemVo> findItem(@PathVariable Long skuId){
        ProductItemVo vo = productService.findItem(skuId);
        return Result.build(vo,ResultCodeEnum.SUCCESS);
    }

    //微服务调用接口
    @GetMapping("/getBySkuId/{skuId}")
    public ProductSku getBySkuId(@PathVariable Long skuId){
        ProductSku productSku = productService.getBySkuId(skuId);
        return productSku;
    }

    @Operation(summary = "更新商品sku销量")
    @PostMapping("/updateSkuSaleNum")
    public Boolean updateSkuSaleNum(@RequestBody List<SkuSaleDto> skuSaleDtoList){
        return productService.updateSkuSaleNum(skuSaleDtoList);
    }
}
